﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using zyconfig;

namespace zyui
{
    public class BookSetting
    {
        /// <summary>
        /// 获取文献的虚拟库室
        /// </summary>
        /// <param name="dlh"></param>
        /// <param name="errorMsg"></param>
        /// <returns></returns>
        public static int getXnks(string dlh, out string errorMsg)
        {
            int xnks = 0; errorMsg = "";
            using (DbOperHandler _open = new Common().Doh())
            {
                _open.Reset();
                _open.ConditionExpress = " 登录号='" + dlh + "' or 条形码='" + dlh + "'";
                if (_open.Exist("馆藏典藏库"))
                {
                    object[] obj = _open.GetFields("馆藏典藏库", "状态,馆藏地址,虚拟库室");
                    if (obj[0].ToString().Trim().Equals("G"))
                    {
                        _open.Reset();
                        _open.ConditionExpress = " 馆藏地址='" + obj[1] + "'";
                        if (_open.GetField("馆藏地址定义", "可外借") != null)
                        {
                            if(Convert.ToInt32(_open.GetField("馆藏地址定义", "可外借").ToString().Trim()) == 1)
                            {
                                xnks = Convert.ToInt32(obj[2]);
                            }
                            else
                                errorMsg = "该文献不可外借！";
                        }
                        else
                            errorMsg = "该文献不可外借！";
                    }
                    else
                        errorMsg = "该文献尚未入藏！";
                }
                else
                {
                    errorMsg = "本馆不存在该条码的文献！";
                }
            }
            return xnks;
        }
    }
}
